home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 7923 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.1 KB  |  67 lines

  1. Newsgroups: comp.lang.c++
  2. Path: in2.uu.net!iglou!news
  3. From: "Abe L. Getchell" <panther@iglou.com>
  4. Subject: Re: A simple question for all the C++ gurus out there!
  5. X-Nntp-Posting-Host: dp-2-14.iglou.net
  6. Content-Type: text/plain; charset=us-ascii
  7. Message-ID: <31221E91.7817@iglou.com>
  8. Sender: news@iglou.com (News Administrator)
  9. Content-Transfer-Encoding: 7bit
  10. Organization: 3DX Studios
  11. References: <3120F95F.659@iglou.com> <31210272.29E69549@eiffel.com>
  12. Mime-Version: 1.0
  13. Date: Wed, 14 Feb 1996 17:40:33 GMT
  14. X-Mailer: Mozilla 2.0 (Win16; I)
  15.  
  16. Guus Leeuw jr. wrote:
  17. > Abe L. Getchell wrote:
  18. > >
  19. > > I am trying to write a public member function that will use a private
  20. > > data member from which it inherited from the base class.  This won't compile.
  21. > > It gives me an error message like "A::a private data member not accessible in
  22. > > class B".  Why won't this work if the prvate data member being inherited from
  23. > > the base class A be a private data member of the derived class?
  24. > When you derive from a class you will only be able to access the public and protected
  25. > members of that [base] class.
  26. > So if your classes are like
  27. >         class A
  28. >         {
  29. >                 public:
  30. >                         A();
  31. >                         ~A();
  32. >                 protected:
  33. >                         int b;
  34. >                 private:
  35. >                         int a;
  36. >         }
  37. >         class B: public A
  38. >         {
  39. >                 public:
  40. >                         B();
  41. >                         ~B();
  42. >                         void do_something() {cout << b << endl;}
  43. >         }
  44. > everything'll be just fine.
  45. > Datamember `A::a' is not accessible from other classes than class A.
  46. > This scheme is of particular use when the base class has datamembers or member
  47. > functions which are not to be inherited by derived classes.
  48. > The protected members, however, will be inherited and thus accessible.
  49. > Hope this explains,
  50. >         Guus Leeuw jr.
  51.  
  52.     Thank you very much for the help!  After many nice replies in the group 
  53. ( and one not so nice one in mail :/ ) I finally understand it. :)  Thank you 
  54. for your help...
  55.  
  56. Abe L. Getchell
  57.